<template>
    <div>


        <!-- {{resourceslist}} -->
        <!--资源分配对应表  多对多角色资源-->
        <br>
    
    
        <br>
        资源分配
        <van-checkbox-group v-model="ids">
            <van-checkbox :name="i.id" v-for="(i,j) in resourceslist" :key="j">{{i.name}}</van-checkbox>
        </van-checkbox-group>

        <br>
        <van-button @click="add">权限分配</van-button>
    </div>
</template>

<script>
    export default {
        data() {
            return {    
                resourceslist:[],
                ids:[],
                roleid:this.$route.query.id
            }
        },
        methods: {
        
            //获取资源
            getresources(){
                this.$axios.get('/user/resourcesadd/').then(res=>{
                    this.resourceslist = res.data.list
                    this.getResour()
                })
            },
            //资源添加
            add(){
                this.$axios.post('/user/perass/',{ids:this.ids,roles:this.roleid}).then(res=>{
                    if(res.data.code == 200){
                        this.$toast.success(res.data.msg)
                    }
                
                })
            },
            //权限添加再次修改展示
            getResour(){
                this.$axios.get('/user/perass/?id='+this.roleid).then(res=>{
                    this.ids = res.data.list
                })
            }
        },
        mounted() {
            this.getresources()
            
        },

    }
</script>

<style scoped>

</style>